#include<stdio.h>
#include <unistd.h>
#include<string.h>
#include<stdlib.h>
#include<fcntl.h>
#define MAX_CMD 1024
int main()
{
  char command[MAX_CMD];
  for( ; ; )
  { 
      printf("minishell$ ");
      fflush(stdout);
      fgets(command, MAX_CMD, stdin);
      command[strlen(command) - 1] = '\0';
      char *argv[MAX_CMD] = {NULL};
    const char *sep = " ";
    argv[0] = strtok(command, sep);
    int i = 1;
    while(i)
    {
      argv[i] = strtok(NULL, sep);
      if(argv[i] == NULL)
        break;
      i++;
    
    }
    //内建命令
    if(strcmp(argv[0], "cd") == 0)
    {
      if(argv[1] != NULL)
      {
        chdir(argv[1]);
        continue;
      }
    }
    if(fork() == 0)
    {
      execvp(argv[0], argv);
      exit(1);
    }
    waitpid(-1, NULL, 0);
  }
  return 0;

}
